home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_asm / as4 / do4.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-30  |  4.0 KB  |  191 lines

  1. /*
  2.  *      MC6804 specific processing
  3.  */
  4.  
  5. #define IMMED   0
  6. #define IND     1
  7. #define OTHER   2
  8.  
  9. /* special addresses */
  10. #define XREG    0x80
  11. #define YREG    0x81
  12. #define SD1REG  0x82
  13. #define SD2REG  0x83
  14. #define ACCUM   0xFF
  15.  
  16.  
  17. char *skip_white();   /* this line added to keep TurboC happy 4/30/88 jec */
  18.  
  19. /*
  20.  *      localinit --- machine specific initialization
  21.  */
  22. localinit()
  23. {
  24.     install("x",XREG);
  25.     install("X",XREG);
  26.     install("y",YREG);
  27.     install("Y",YREG);
  28.     install("a",ACCUM);
  29.     install("A",ACCUM);
  30. }
  31.  
  32. /*
  33.  *      do_op --- process mnemonic
  34.  */
  35. do_op(opcode,class)
  36. {
  37.     int     dist;   /* relative branch distance */
  38.     int     amode;  /* indicated addressing mode */
  39.     int     r1;     /* first eval() for mvi */
  40.  
  41.     if (( *Operand == '[' ) || ( *Operand == ','))
  42.         amode = IND;
  43.     else if( *Operand == '#' )
  44.         amode = IMMED;
  45.     else
  46.         amode = OTHER;
  47.  
  48.     switch(class){
  49.         case INH:                       /* inherent addressing */
  50.             emit(opcode);
  51.             return;
  52.         case APOST:             /* A address in mem follows opcode */
  53.             emit(opcode);
  54.             emit(ACCUM);
  55.             return;
  56.         case REL:                       /* short relative branches */
  57.             eval();
  58.             dist = Result - (Pc+1);
  59.             if( (dist >15 || dist <-16) && Pass==2){
  60.                 error("Branch out of Range");
  61.                 dist = -1;
  62.                 }
  63.             emit(opcode + (dist&0x1F));
  64.             return;
  65.         case BTB:
  66.         case SETCLR:
  67.             eval();
  68.             if(Result <0 || Result >7){
  69.                 error("Bit Number must be 0-7");
  70.                 return;
  71.                 }
  72.             emit( opcode + Result);
  73.             if(*Optr++ != ',')error("SYNTAX");
  74.             eval();
  75.             emit(lobyte(Result));
  76.             if( class == SETCLR )
  77.                 return;
  78.             if(*Optr++ != ',')error("SYNTAX");
  79.             eval();
  80.             dist = Result - (Old_pc+3);
  81.             if( (dist >127 || dist <-128) && Pass==2){
  82.                 error("Branch out of Range");
  83.                 dist = -3;
  84.                 return;
  85.                 }
  86.             emit(lobyte(dist));
  87.             return;
  88.         case EXT:               /* jsr, jmp */
  89.             eval();
  90.             emit(opcode | (hibyte(Result) & 0x0F));
  91.             emit(lobyte(Result));
  92.             return;
  93.         case BPM:       /* brset/clr 7,accum,target */
  94.             emit(opcode);
  95.             emit(ACCUM);
  96.             eval();
  97.             dist = Result - (Old_pc + 3);
  98.             if ((dist > 127 || dist < -128) && Pass == 2) {
  99.                 error("Branch out of range");
  100.                 dist = -3;
  101.                 return;
  102.                 }
  103.             emit(lobyte(dist));
  104.             return;
  105.         case MVI:
  106.             eval();
  107.             r1 = Result;    /* save result */
  108.             if (*Optr++ != ',')
  109.                 warn("Missing ','");
  110.             eval();
  111.             mvi(opcode,r1,Result);
  112.             return;
  113.         case CLRX:      /* mvi xreg,0 */
  114.             mvi(opcode,XREG,0);
  115.             return;
  116.         case CLRY:      /* mvi yreg,0 */
  117.             mvi(opcode,YREG,0);
  118.             return;
  119.         case LDX:       /* mvi xreg data */
  120.             if (amode == IMMED) Optr++;
  121.             eval();
  122.             mvi(opcode,XREG,Result);
  123.             return;
  124.         case LDY:       /* mvi yreg data */
  125.             if (amode == IMMED) Optr++;
  126.             eval();
  127.             mvi(opcode,YREG,Result);
  128.             return;
  129.         case NOIMM:
  130.             if( amode == IMMED ){
  131.                 error("Immediate Addressing Illegal");
  132.                 return;
  133.                 }
  134.         case GEN:
  135.             if ( amode == IMMED ) {
  136.                 Optr++;
  137.                 eval();
  138.                 emit(opcode | 0x08);
  139.                 emit(Result);
  140.                 return;
  141.                 }
  142.             if( amode == IND ){
  143.                 Optr++;
  144.                 eval();
  145.                 if ((*Optr != ']') && (*Operand != ','))
  146.                     warn("Missing ']'");
  147.                 if (Result != XREG && Result != YREG) {
  148.                     error("Operand must be $80 or $81");
  149.                     emit(opcode);
  150.                     return;
  151.                 }
  152.                 emit(opcode | ((Result&0x01)<<4));
  153.                 return;
  154.                 }
  155.             eval();
  156.             if (XREG <= Result && Result <=SD2REG){
  157.                 /*check for short direct cases*/
  158.                 if ( opcode==0xE6 ) {   /* inc */
  159.                     emit(0xA8 + (Result-XREG));
  160.                     return;
  161.                     }
  162.                 if ( opcode==0xE7 ) { /* dec */
  163.                     emit(0xB8 + (Result-XREG));
  164.                     return;
  165.                     }
  166.                 if ( opcode==0xE0 ) { /* lda */
  167.                     emit(0xAC | (Result-XREG));
  168.                     return;
  169.                     }
  170.                 if ( opcode==0xE1 ) { /* sta */
  171.                     emit(0xBC | (Result-XREG));
  172.                     return;
  173.                     }
  174.                 }
  175.             /* else direct addressing */
  176.             emit( opcode | 0x18);
  177.             emit(lobyte(Result));
  178.             return;
  179.         default:
  180.             fatal("Error in Mnemonic table");
  181.         }
  182. }
  183.  
  184. mvi(op,to,from)
  185. int op,to,from;
  186. {
  187.     emit(op);
  188.     emit(to);
  189.     emit(from);
  190. }
  191.